package com.uton.rfidcontroller.viewmodel.activity_model;

import android.databinding.ObservableBoolean;
import android.databinding.ObservableField;

import com.uton.rfidcontroller.common.interfaces.INetController;
import com.uton.rfidcontroller.common.net.RetrofitFactory;
import com.uton.rfidcontroller.model.ScanCarDetailModel;
import com.uton.rfidcontroller.viewmodel.base.BaseViewModel;

import java.util.HashMap;

/**
 * Created by 王家宝 on 2017/9/25.
 * Email:639586819@qq.com
 * Tel:18241150668
 */

public abstract class ScanDetailActivityViewModel extends BaseViewModel {

    public final ObservableBoolean locked = new ObservableBoolean(false);
    public final ObservableBoolean isError = new ObservableBoolean(false);
    public final ObservableField<String> errMsg = new ObservableField<>("");
    //RFID标签号
    public final ObservableField<String> cardId = new ObservableField<>("");
    //车辆品牌
    public final ObservableField<String> cBrand = new ObservableField<>("");
    //车牌号
    public final ObservableField<String> plateNumber = new ObservableField<>("");
    //车辆颜色
    public final ObservableField<String> carColour = new ObservableField<>("");

    private String carId;

    private String id;

    public ScanDetailActivityViewModel(String carId, String id) {
        this.carId = carId;
        this.id = id;
        refreshData();
    }

    @Override
    public void refreshData() {
        HashMap<String, Object> tempData = new HashMap<>();
        tempData.put("carId", carId);
        tempData.put("carRfidId", id);
        go(RetrofitFactory.getInstance().scanCarDetail(tempData), new INetController<ScanCarDetailModel>() {
            @Override
            public void onSuccess(ScanCarDetailModel response) {
                cardId.set(response.getRfidLabelId());
                cBrand.set(response.getCBrand());
                plateNumber.set(response.getPlateNumber());
                carColour.set(response.getCarColour());
            }

            @Override
            public void onError() {

            }

            @Override
            public void onComplete() {

            }
        });

    }

    public abstract void showCarDetail();

    public abstract void commitRet();

}
